class CustomerAccount {
    public String accountType;
    public double balance;
    
    public CustomerAccount(String accType, Double bal){
        this.accountType = accType;
        this.balance = bal;
    }
    
    public String getAccountType(){
        return accountType;
    }
    
    public void setAccountType(String accType){
        accountType = accType;
    }
    
    public double getBalance(){
        return balance;
    }
    
    public void setBalance(double bal){
        balance = bal;
    }
    
    synchronized public void InfoAccount(){
        System.out.println("["+ this.accountType + ", " + this.balance + "]");
    }
}

class TransferManager implements Runnable {
    public static int transferCount = 0;
    public CustomerAccount accSend;
    public CustomerAccount accReceive;
    public double amount;
    
    public TransferManager(CustomerAccount send, CustomerAccount receive, double a){
        this.accSend = send;
        this.accReceive = receive;
        this.amount = a;
    }
    
    synchronized public void run(){
        System.out.println("Before transferring:");
        accSend.InfoAccount();
        accReceive.InfoAccount();
        
        double sendBalance = accSend.getBalance();
        double receiveBalance = accReceive.getBalance();
        
        if(amount > 0 && amount < sendBalance){
            System.out.println("After transferring " + amount);
            sendBalance = sendBalance - amount;
            accSend.setBalance(sendBalance);
            
            receiveBalance = receiveBalance + amount;
            accReceive.setBalance(receiveBalance);
            
            transferCount++;
            
            accSend.InfoAccount();
            accReceive.InfoAccount();
            System.out.println("Number of transferring: " + transferCount);
        } else {
            System.out.println("Transfering not complete because amount not valid!!!");
        }
    }
}

class AccountManager {
    public static void main(String[] args) {
        CustomerAccount acc1 = new CustomerAccount("Acc 1", 720.0);
        CustomerAccount acc2 = new CustomerAccount("Acc 2", 500.0);
        CustomerAccount acc3 = new CustomerAccount("Acc 3", 1200.0);
        CustomerAccount acc4 = new CustomerAccount("Acc 4", 1500.0);
        
        TransferManager transfer1 = new TransferManager(acc1, acc2, 300.0);
        TransferManager transfer2 = new TransferManager(acc3, acc4, 200.0);
        
        Thread t1 = new Thread(transfer1);
        Thread t2 = new Thread(transfer2);
        
        t1.start();
        t2.start();
        t2.setPriority(1);
    }
}